package com.yzyz.utils;

import javax.servlet.http.HttpServletRequest;
import com.yzyz.utils.error.Error;

/**
 * 
 * @author David Sun
 * @Date   2010-4-7
 *
 */
public class ValidateUtils {
	public static boolean isNull(String content) {
		if(content == null || content.length() == 0) {
			return true;
		}
		return false;
	}
	
	public static int validateNewRoute(HttpServletRequest request) {
		String price 	= request.getParameter("price");
		String name 	= request.getParameter("name");
		String contents = request.getParameter("contents");
		if(ValidateUtils.isNull(name)) {
			return Error.ROUTE_NAME_REQUIRED;

		}
		if(ValidateUtils.isNull(price)) {
			return Error.ROUTE_PRICE_REQUIRED;
		}
		if(ValidateUtils.isNull(contents)) {
			return Error.ROUTE_CONTENTS_REQUIRED;
		}
		if(ValidateUtils.isNull(request.getParameter("level"))) {
			return Error.ROUTE_LEVEL_REQUIRED;
		}
		return Error.SUCCESS;
	}
	
	public static int validateEditRoute(HttpServletRequest request) {
		int result = ValidateUtils.validateNewRoute(request);
		if(result != Error.SUCCESS) {
			return result; 
		} else {
			if(ValidateUtils.isNull(request.getParameter("routeId"))) {
				return Error.ROUTE_ID_REQUIRED;
			}
		}
		return Error.SUCCESS;
	}
	
	public static boolean isEquals(String arg1, String arg2){
		if(ValidateUtils.isNull(arg1) && ValidateUtils.isNull(arg2)){
			return false;
		}
		if(arg1.equals(arg2)){
			return true;
		} else {
			return false;
		}
	}
}
